#!/bin/bash
# 备份验证脚本

echo "=========================================="
echo "备份验证工具"
echo "=========================================="

# 检查必要文件
echo "检查必要文件..."
required_files=(
    "ifconfig.txt"
    "network_services.txt" 
    "dns_config.txt"
    "routing_table.txt"
    "hosts.txt"
    "redis_server_info.txt"
)

missing_files=()
for file in "${required_files[@]}"; do
    if [ -f "$file" ]; then
        echo "   ✅ $file"
    else
        echo "   ❌ $file"
        missing_files+=("$file")
    fi
done

# 检查SystemConfiguration目录
echo ""
echo "检查系统配置..."
if [ -d "SystemConfiguration" ]; then
    config_count=$(ls SystemConfiguration 2>/dev/null | wc -l)
    echo "   ✅ SystemConfiguration目录已备份 ($config_count 个文件)"
else
    echo "   ⚠️  SystemConfiguration目录未备份（可能需要sudo权限）"
fi

# 统计代理配置文件
echo ""
echo "检查代理配置..."
proxy_files=$(ls proxy_*.txt 2>/dev/null | wc -l)
if [ $proxy_files -gt 0 ]; then
    echo "   ✅ 备份了 $proxy_files 个代理配置文件"
    
    # 显示代理状态
    enabled_proxies=0
    for proxy_file in proxy_*.txt; do
        if [ -f "$proxy_file" ] && grep -q "Enabled: Yes" "$proxy_file"; then
            ((enabled_proxies++))
        fi
    done
    echo "   📊 其中 $enabled_proxies 个代理处于启用状态"
else
    echo "   ❌ 未找到代理配置文件"
fi

# 检查DNS配置
echo ""
echo "检查DNS配置..."
dns_files=$(ls dns_*.txt 2>/dev/null | wc -l)
if [ $dns_files -gt 0 ]; then
    echo "   ✅ 备份了 $dns_files 个DNS配置文件"
else
    echo "   ❌ 未找到DNS配置文件"
fi

# 总结
echo ""
echo "=========================================="
if [ ${#missing_files[@]} -eq 0 ]; then
    echo "✅ 备份验证通过！所有重要配置都已备份"
else
    echo "⚠️  备份不完整，缺少以下文件:"
    for file in "${missing_files[@]}"; do
        echo "   - $file"
    done
fi
echo "=========================================="
